﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Solver;

namespace SmileSolver
{
    /// <summary>
    /// Interaction logic for CardControl.xaml
    /// </summary>
    public partial class CardControl : UserControl
    {
        public CardControl()
        {
            InitializeComponent();
            DataContextChanged += CardControl_DataContextChanged;

            SmileTemplateSelector selector = (SmileTemplateSelector)FindResource("SmileSelector");

            DataTemplate unknown = (DataTemplate)FindResource("UnknownTemplate");
            selector.Unknown = unknown;

            DataTemplate bot_eye = (DataTemplate)FindResource("EyeBottom");
            DataTemplate top_eye = (DataTemplate)FindResource("EyeTop");
            DataTemplate le_eye = (DataTemplate)FindResource("EyeLeft");
            DataTemplate ri_eye = (DataTemplate)FindResource("EyeRight");
            //
            DataTemplate bot_smile = (DataTemplate)FindResource("SmileBottom");
            DataTemplate top_smile = (DataTemplate)FindResource("SmileTop");
            DataTemplate le_smile = (DataTemplate)FindResource("SmileLeft");
            DataTemplate ri_smile = (DataTemplate)FindResource("SmileRight");
            //
            selector.LeftEye = le_eye;
            selector.RightEye = ri_eye;
            selector.TopEye = top_eye;
            selector.BottomEye = bot_eye;
            //
            selector.LeftSmile = le_smile;
            selector.RightSmile = ri_smile;
            selector.TopSmile = top_smile;
            selector.BottomSmile = bot_smile;
        }

        void CardControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                OneCard card = (OneCard)e.NewValue;                
            }
        }
    }

    public class SmileValueConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            HalfSmile smile = (HalfSmile)value;            
            SmileDescription sm_desc = new SmileDescription();
            sm_desc.Smile = smile;
            if (parameter.ToString() == "Top")
                sm_desc.Side = SmileSide.Top;
            if (parameter.ToString() == "Right")
                sm_desc.Side = SmileSide.Right;
            if (parameter.ToString() == "Bottom")
                sm_desc.Side = SmileSide.Bottom;
            if (parameter.ToString() == "Left")
                sm_desc.Side = SmileSide.Left;

            return sm_desc;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public enum SmileSide { Top, Right, Bottom, Left };

    public class SmileDescription
    {
        public HalfSmile Smile { get; set; }
        public SmileSide Side { get; set; }
    }

}
